package com.me.myFramework.aop22.aop112.intercept.method;

import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

/**
 * 《AOP-112》：  <br><br>
 *
 * 把切面逻辑抽取到单独接口中，后续通过组合模式调用 before()
 *
 * @author ME
 */
public class MethodBeforeAdviceInterceptor112 implements MethodInterceptor112 {

    private final MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor112(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(Method method, Object[] args, Object target) throws Throwable {
        this.advice.before(method, args, target);
        return method.invoke(target, args);
    }

}
